#include "MA730.h"
#include "asm/spi.h"
#include "app_config.h"
#include "asm/gpio.h"
#define CS_PIN IO_PORTA_07
#define user_spi 2
const struct spi_platform_data spi1_p_data;
const struct spi_platform_data spi2_p_data = {
    .port = TCFG_HW_SPI2_PORT,
    .clk = TCFG_HW_SPI2_BAUD,
    .mode = TCFG_HW_SPI2_MODE,
    .role = SPI_ROLE_MASTER};

void init_spi_cs_pin()
{
    gpio_set_direction(CS_PIN, 0);
    gpio_set_die(CS_PIN, 1);
    gpio_set_pull_up(CS_PIN, 1);
    gpio_set_pull_down(CS_PIN, 0);
}

void spi_cs_set(u8 c)
{
    gpio_set_output_value(CS_PIN, c);
    delay(10);
}
void ma730_spi_init()
{
    printf("ma730 init!");
    spi_open(user_spi);
    init_spi_cs_pin(CS_PIN);
}

void ma730_get_byte()
{
    u8 data[2] = {0};
    spi_cs_set(0);
    spi_dma_recv(user_spi, data, 2);
    spi_cs_set(1);
    printf("read data %X %X", data[0],data[1]);
}